import * as types from './mutation_types'
import _ from 'lodash'
// 初始化播放器
export const openP = ({
  commit
}, {
  list,
  index,
  mode
}) => {
  commit(types.SET_CURRENTINDEX, index)
  commit(types.SET_PLAYING, true)
  commit(types.SET_PREV, list)
  if (mode) {
    commit(types.SET_PLAYLIST, _.shuffle(list))
    commit(types.SET_MODE, mode)
  } else {
    commit(types.SET_PLAYLIST, list)
  }
  commit(types.SET_FULLSCREEN, true)
  // if(mode)
}

// 切歌
export const next = ({
  commit,
  state
}, id) => {
  commit(types.SET_FULLSCREEN, true)
  // 如果当前是随机播放列表 通过id来找到index
  const index = state.playList.findIndex((item) => {
    return item.id === id
  })
  commit(types.SET_CURRENTINDEX, index)
  commit(types.SET_PLAYING, true)
}

// 更换播放模式 / 切换播放列表
export const changePlayList = ({
  commit
}, list) => {
  commit(types.SET_PLAYLIST, list)
}
